/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import DAO.NhanVienDao;
import POJO.NhanVien;
import javax.swing.JOptionPane;

/**
 *
 * @author Khôi
 */
public class frThayDoiThongTinCaNhan extends javax.swing.JInternalFrame {

	/**
	 * Creates new form LoaiSanPhamGui
	 */
	/**
	 * Chủ yếu dùng dể đổi mật khẩu của người dùng Không thay đổi một khẩu
	 * khi đăng nhập ở quyền sa
	 */
	public frThayDoiThongTinCaNhan() {
		initComponents();
		txTen.setText(Var.NV.getTenNV());
		txUser.setText(Var.NV.getUserName());
		txPass.setText(Var.NV.getPassWord());
	}

	/**
	 * This method is called from within the constructor to initialize the
	 * form. WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
       // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
       private void initComponents() {

              jPanel1 = new javax.swing.JPanel();
              jLabel2 = new javax.swing.JLabel();
              txTen = new javax.swing.JTextField();
              jLabel6 = new javax.swing.JLabel();
              txUser = new javax.swing.JTextField();
              jLabel7 = new javax.swing.JLabel();
              txPass = new javax.swing.JPasswordField();
              jButton1 = new javax.swing.JButton();
              jButton2 = new javax.swing.JButton();
              jLabel8 = new javax.swing.JLabel();
              txRepass = new javax.swing.JPasswordField();
              jPanel4 = new javax.swing.JPanel();
              jLabel5 = new javax.swing.JLabel();

              setClosable(true);
              setIconifiable(true);
              setMaximizable(true);

              jLabel2.setText("Tên nhân viên:");

              jLabel6.setText("Username:");

              txUser.setEditable(false);

              jLabel7.setText("Password:");

              jButton1.setText("Lưu");
              jButton1.setToolTipText("Cộng thêm sản phẩm mới vào sản phẩm");
              jButton1.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jButton1ActionPerformed(evt);
                     }
              });

              jButton2.setText("Hủy");
              jButton2.setToolTipText("Gọi form nhập sản phẩm mới");

              jLabel8.setText("Re Password:");

              javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
              jPanel1.setLayout(jPanel1Layout);
              jPanel1Layout.setHorizontalGroup(
                     jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(83, 83, 83)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel6)
                                   .addComponent(jLabel2)
                                   .addComponent(jLabel7)
                                   .addComponent(jLabel8))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                   .addComponent(txRepass)
                                   .addComponent(txPass, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
                                   .addComponent(txUser, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
                                   .addComponent(txTen))
                            .addContainerGap(143, Short.MAX_VALUE))
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton2)
                            .addGap(25, 25, 25))
              );
              jPanel1Layout.setVerticalGroup(
                     jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(24, 24, 24)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(txTen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jLabel2))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(txUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jLabel6))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(txPass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jLabel7))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(txRepass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jLabel8))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jButton1)
                                   .addComponent(jButton2))
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );

              jLabel5.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
              jLabel5.setText("THAY ĐỔI THÔNG TIN CÁ NHÂN");

              javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
              jPanel4.setLayout(jPanel4Layout);
              jPanel4Layout.setHorizontalGroup(
                     jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                            .addContainerGap(71, Short.MAX_VALUE)
                            .addComponent(jLabel5)
                            .addContainerGap(72, Short.MAX_VALUE))
              );
              jPanel4Layout.setVerticalGroup(
                     jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel4Layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jLabel5)
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );

              javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
              getContentPane().setLayout(layout);
              layout.setHorizontalGroup(
                     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(layout.createSequentialGroup()
                            .addGap(0, 0, 0)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                   .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(0, 0, 0))
              );
              layout.setVerticalGroup(
                     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(layout.createSequentialGroup()
                            .addGap(0, 0, 0)
                            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, 0)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 4, Short.MAX_VALUE))
              );

              pack();
       }// </editor-fold>//GEN-END:initComponents

       private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
		// TODO add your handling code here:
		NhanVien tmp = new NhanVien(Var.NV);
		String ten = txTen.getText().trim();
		String pa = txPass.getText().trim();
		String rpa = txRepass.getText().trim();
		if (ten.equals("sa")) {
			return;
		}
		tmp.setTenNV(ten);
		if (!pa.equals(rpa)) {
			JOptionPane.showMessageDialog(this, "Nhập sai mật khẩu xác nhận. Nhập lại", "Thông báo lỗi", JOptionPane.ERROR_MESSAGE);
			txPass.requestFocus();
			return;
		}
		NhanVienDao dao = new NhanVienDao();
		try {
			if (dao.capNhat(tmp)) {
				JOptionPane.showMessageDialog(this, "Cập nhật thành công ", "Thông báo ", JOptionPane.INFORMATION_MESSAGE);

			}
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, "Cập nhật bị lỗi", "Thông báo lỗi", JOptionPane.ERROR_MESSAGE);

		}


       }//GEN-LAST:event_jButton1ActionPerformed
       // Variables declaration - do not modify//GEN-BEGIN:variables
       private javax.swing.JButton jButton1;
       private javax.swing.JButton jButton2;
       private javax.swing.JLabel jLabel2;
       private javax.swing.JLabel jLabel5;
       private javax.swing.JLabel jLabel6;
       private javax.swing.JLabel jLabel7;
       private javax.swing.JLabel jLabel8;
       private javax.swing.JPanel jPanel1;
       private javax.swing.JPanel jPanel4;
       private javax.swing.JPasswordField txPass;
       private javax.swing.JPasswordField txRepass;
       private javax.swing.JTextField txTen;
       private javax.swing.JTextField txUser;
       // End of variables declaration//GEN-END:variables
}
